
enum {
	TIMER_LOOP_FOREVER=0,
	TIMER_LOOP_ONCE,
	TIMER_LOOP_TWICE,
};

enum {
	TIME_IN_SECONDS=0,
	TIME_IN_MILLISECONDS, // mSec
	TIME_IN_MICROSECONDS, // uSec (default units upon setup)
	TIME_IN_PICOSECONDS,  // pSec
};

enum {
	TIMER_EXPIRED=0,
	TIMER_EXPIRED_EARLY,
	TIMER_EXPIRED_LATE,
	TIMER_RUNNING,
};

class CTimer;
class CHardware;

class ITimerCallback abstract {
	public:
		virtual void Timer_Expired(CTimer* timer) = 0;

};


class CTimer {
	private: // Generic timer stuff
		double timeLeft;
		double initialTime;
		int timerEnabled;

	private: // vblank and other IRQ-related variables. if vblank timer mode is enabled, the timer loops endlessly
		CHardware* hardware;
		ITimerCallback* callback;
		int isInVblankMode;
		int destCpuLine;
		ICpu* destCpu;
		
	public: // Hardware calls
			//CTimer();
			CTimer(CHardware* hardware);
			double GetTimeLeft() { return timeLeft; }
			void SetStatus(int status); // enable or disable the timer
			void SetTimerCallback(ITimerCallback* cb);
			void SetLength   (double length); // Sets the length of the timer cycle, takes effect when the timer resets
			void SetupAsVBlank   (double interval, ICpu* dest, int line); // Set the timer as a vblank controller
			void Reset(); // Reset and enable the timer
			void Stop();  // Stop and disable the timer
			void Run (double time); // Run the timer

};